//
//  NiuRenTrade.m
//  RedManStock
//
//  Created by lanou3g on 15/7/22.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "NiuRenTrade.h"
#import "SimpleStock.h"
@implementation NiuRenTrade

#pragma mark - 懒加载 -
- (SimpleStock *)stock{
    if (_stockSB==nil) {
        _stockSB=[[SimpleStock alloc]init];
    }
    return _stockSB;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
    if ([key isEqualToString:@"id"]) {
        self.niurenTrade_id=[NSString stringWithFormat:@"%@",value];
    }
    if ([key isEqualToString:@"price"]) {
        self.priceSB=[NSString stringWithFormat:@"%@元",value];
    }
    if ([key isEqualToString:@"date"]) {
        
//        非常重要
        
        NSDate *nd=[NSDate dateWithTimeIntervalSince1970:(float)[value floatValue]];
        NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
        [dateFormatter setDateFormat:@"MM-dd HH:mm"];
        NSString *dateStr=[dateFormatter stringFromDate:nd];
        self.dateSB=dateStr;
    }
    if ([key isEqualToString:@"rate"]) {
        CGFloat number=[(NSNumber *)value floatValue]*100;
        self.rateSB=[NSString stringWithFormat:@"%.2f%%",number];
    }
    
    //每次都要测试
    self.tradeStr=[NSString stringWithFormat:@"成交价%@，收益率%@",self.priceSB,self.rateSB];
    
    if ([key isEqualToString:@"stock"]) {
        NSDictionary *stock=(NSDictionary *)value;
        self.stock.code=[NSString stringWithFormat:@"%@",[stock objectForKey:@"code"]];
        self.stock.name=[NSString stringWithFormat:@"%@",[stock objectForKey:@"name"]];
        self.simpleStockStr=[NSString stringWithFormat:@"%@（%@）",self.stock.name,self.stock.code];
    }
    if ([key isEqualToString:@"type"]) {
        NSString *str=[NSString stringWithFormat:@"%@",value];
        if ([str isEqualToString:@"sell"]) {
            self.typeSB=[NSString stringWithFormat:@"卖出"];
        }
        else if([str isEqualToString:@"buy"]){
            self.typeSB=[NSString stringWithFormat:@"买入"];
        }
    }
    
}

@end
